/*
 * Copyright 2025-2026 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package glz.hawk.app;

import glz.hawk.bookstore.mapper.BookMapper;
import glz.hawk.bookstore.model.Book;
import glz.hawk.bookstore.model.BookExample;
import glz.hawk.bookstore.model.BookWithBLOBs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * This class is responsible for
 *
 * @author Zhang Peng
 */
public class MyExampleApplication {

    @Autowired
    private BookMapper bookMapper;

    public static void main(String[] args) {
        try (ConfigurableApplicationContext context = SpringApplication.run(MyExampleApplication.class, args)) {
            MyExampleApplication application = context.getBean(MyExampleApplication.class);
            application.queryBook();
        }
    }

    public void queryBook() {
        BookExample bookExample = new BookExample();
        bookExample.setOrderByClause("book_id desc");
        bookExample.createCriteria().andBookIdEqualTo(new BigDecimal(10));
        bookExample.or().andBookIdIn(Arrays.asList(new BigDecimal(10), new BigDecimal(10), new BigDecimal(10)));
        List<Book> list = bookMapper.selectByExample(bookExample);
        list.forEach(book -> {
            System.out.println("book name = " + book.getBookName());
        });
    }

    public void createBook() {
        BookWithBLOBs book = new BookWithBLOBs();
        book.setBookId(new BigDecimal(10));
        book.setBookName("four monks");
        book.setBookPrice(new BigDecimal(10));
        bookMapper.insertSelective(book);
    }
}
